home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / LIBRARY / DMTDEMOS / GETROOT.PAS < prev    next >
Pascal/Delphi Source File  |  1994-07-02  |  4KB  |  134 lines

  1. program GetRootSample;
  2.  
  3. (*
  4.  
  5.  Every DOS disk has a root directory with entries that specify the volume's
  6.  name, files, and other directories. This program reads the root directory
  7.  sectors for the drive specified and displays the root directory entries.
  8.  
  9. *)
  10.  
  11.  uses crt, DMT;
  12.  
  13.  var
  14.    RootDirBuffer    : array[ 1..16 ] of RootDirEntryStruct; { The RootDirEntry data type is defined in the DMT unit }
  15.  
  16.    LogDrvs          : ListOfDrvs;        { The ListOfDrvs data type is defined in the DMT unit }
  17.  
  18.    BPBbuffer        : DevParamsStruct;   { The DevParamsStruct data type is defined in the DMT unit }
  19.  
  20.    StartRootSector,
  21.    Head,
  22.    Track,
  23.    Sect,
  24.    SectCounter,
  25.    NumOfRootSects,
  26.    Count            : word;
  27.  
  28.    DrvsCount,
  29.    Index            : byte;
  30.  
  31.    DrvLetter        : char;
  32.  
  33. begin
  34.   fillchar( RootDirBuffer, sizeof( RootDirBuffer ), #0 );
  35.   Color( 7, 0 );
  36.   clrscr;
  37.  
  38.   GetDrvs( LogDrvs, DrvsCount );   { Call GetDrvs procedure }
  39.  
  40.   write( #13#10, 'Select drive ( ');
  41.  
  42.   for Index := 1 to DrvsCount do
  43.     write( LogDrvs[ Index ], ': ' );
  44.  
  45.   write( ') [ :]' );
  46.   gotoxy( wherex - 3, wherey );
  47.  
  48.   DrvLetter := upcase( readkey );
  49.   writeln( DrvLetter );
  50.  
  51.   GetBPB( DrvLetter, BPBbuffer );    { Call GetBPB procedure }
  52.  
  53.   if ( ErrFlag ) then
  54.     begin
  55.       writeln( #7 );
  56.       writeln( ShowError( GetErrCode ) );
  57.     end
  58.   else
  59.     begin
  60.       clrscr;
  61.       writeln( '      ROOT DIRECTORY SECTOR ENTRIES ' );
  62.       writeln;
  63.       writeln( ' Filename            Size       Starting Cluster' );
  64.       writeln;
  65.       window( 1, 5, 80, 25 );
  66.  
  67.       with BPBbuffer do
  68.         begin
  69.  
  70.           (* Determines the number of root directory sectors to read *)
  71.  
  72.           NumOfRootSects := ( MaxRootEntries * 32 ) div BytesPerSect;
  73.  
  74.           (* Determines the start of the first root directory sector *)
  75.  
  76.           StartRootSector := ( NumOfFATs * SectsPerFAT ) + HiddenSects + BootSects;
  77.  
  78.           for SectCounter := StartRootSector to ( StartRootSector + NumOfRootSects - 1 ) do
  79.             begin
  80.  
  81.               (*
  82.                  Translates a logical root directory sector number into a physical
  83.                  sector consisting of head, track, and sector numbers.
  84.               *)
  85.  
  86.               Head  := ( SectCounter div SectsPerTrack ) mod NumOfHeads;
  87.               Track := SectCounter div ( SectsPerTrack * NumOfHeads );
  88.               Sect  := SectCounter mod SectsPerTrack;
  89.  
  90.  
  91.               (*
  92.                  Reads a root directory sector from disk and place it into a
  93.                  buffer.
  94.               *)
  95.  
  96.               ReadSect( DrvLetter, Head, Track, Sect, 1, addr( RootDirBuffer ) );
  97.  
  98.  
  99.               (* Displays 16 root directory entries *)
  100.  
  101.               for Count := 1 to 16 do
  102.                 begin
  103.  
  104.                   with RootDirBuffer[ Count ] do
  105.                     if ( FileName[ 1 ] <> #0 ) then
  106.                       begin
  107.                         write( FileName, '.', Extension, InsComma( FileSize ):15, InsComma( FirstCluster ):15 );
  108.  
  109.                         if ( FileName[ 1 ] = chr( 229 ) ) then
  110.                           write( 'File deleted!': 24 );
  111.  
  112.                          writeln;
  113.                       end
  114.                     else
  115.                       begin
  116.                         GetEnter;
  117.                         exit;
  118.                       end;
  119.  
  120.                   if ( wherey = 20 ) then
  121.                     begin
  122.                       write( #13#10, ' --- More ---' );
  123.                       readln;
  124.                       clrscr;
  125.                     end;
  126.  
  127.                 end;
  128.             end;
  129.         end;
  130.     end;
  131.   GetEnter;
  132. end.
  133.  
  134.